package com.nc.cloud.admin.rpc;

/**
 * @Description
 * @ClassName UserRest
 * @Author NC—Cloud
 * @date 2020.04.03 14:15
 */

import com.ace.cache.annotation.Cache;
import com.nc.cloud.admin.entity.Menu;
import com.nc.cloud.admin.rpc.service.PermissionService;
import com.nc.cloud.api.vo.authority.PermissionInfo;
import com.nc.cloud.api.vo.user.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.misc.Request;

import javax.xml.ws.Response;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api")
public class UserRest {

    @Autowired
    private PermissionService permissionService;



    @Cache(key="permission")
    @RequestMapping(value = "/permissions", method = RequestMethod.GET)
    public @ResponseBody
    List<PermissionInfo> getAllPermission(){
        return null;
    }

    @Cache(key="permission:u{1}")
    @RequestMapping(value = "/user/un/{userName}/permissions", method = RequestMethod.GET)
    public @ResponseBody List<PermissionInfo> getPermissionByUserName(@PathVariable("userName") String userName){
        //return permissionService.(userName);
        return null;
    }

    /**
     * 登陆调用方法 Feign方法
     * **/
    @RequestMapping(value = "/user/validate", method = RequestMethod.POST)
    public @ResponseBody UserInfo validate(@RequestBody Map<String,String> body){
        UserInfo userInfo = permissionService.validate(body.get("userName"),body.get("password"));
        System.out.println("登陆用户信息:"+userInfo.getCode());
        System.out.println("登陆用户信息:"+userInfo.getUid());
        return userInfo;
    }
}
